home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0078_How to detect if disk exists.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  896 b   |  30 lines

  1. {
  2. Here is a function I've written to test if a disk is in a drive (without
  3. generating the Windows error message).  There may be a better way of doing
  4. it in Delphi 2, but this is how it's done in Delphi 1.x:
  5. }
  6.  
  7. function DiskExists(Drive: Char): Boolean;
  8. var
  9.   ErrorMode: Word;
  10. begin
  11.   Drive := UpCase(Drive);
  12.   { Make sure drive is a valid letter }
  13.   if not (Drive in ['A'..'Z']) then
  14.     raise EConvertError.Create('Not a valid drive letter');
  15.   { Turn off critical errors }
  16.   ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
  17.   try
  18.     Application.ProcessMessages;
  19.     Result := (DiskSize(Ord(Drive) - Ord('A') + 1) <> -1);
  20.   finally
  21.     { Restore the old error mode }
  22.     SetErrorMode(ErrorMode);
  23.     Application.ProcessMessages;
  24.   end;
  25. end;
  26.  
  27. If you want to test if a drive exists, with or without a disk in it, the
  28. take a look at the API call GetDriveType()...
  29.  
  30.